package com.example.demo.socket;

import com.example.demo.util.StringUtil;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TCPServerThread extends Thread {
    private Socket socket;

    public TCPServerThread(Socket socket){
        this.socket = socket;
    }

    @Override
    public void run() {
        try{
            OutputStream outputStream = socket.getOutputStream();
            InputStream inputStream = socket.getInputStream();

            String content = StringUtil.readFileContent(inputStream,"utf-8");

            System.out.println("content:"+content);

            content = "message:"+content;

            outputStream.write(content.getBytes());

            inputStream.close();
            outputStream.close();
            socket.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
